package cn.iocoder.yudao.module.signature.dal.mysql.application;

import cn.hutool.core.collection.CollectionUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.signature.controller.admin.application.vo.ApplicationInfoPageReqVO;
import cn.iocoder.yudao.module.signature.dal.dataobject.application.ApplicationInfoDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 应用 Mapper
 *
 * @author base
 */
@Mapper
public interface ApplicationInfoMapper extends BaseMapperX<ApplicationInfoDO> {

    default PageResult<ApplicationInfoDO> selectPage(ApplicationInfoPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ApplicationInfoDO>()
                .eqIfPresent(ApplicationInfoDO::getId, reqVO.getId())
                .eqIfPresent(ApplicationInfoDO::getUserId, reqVO.getUserId())
                .likeIfPresent(ApplicationInfoDO::getApplicationName, reqVO.getApplicationName())
                .eqIfPresent(ApplicationInfoDO::getApplicationStatus, reqVO.getApplicationStatus())
                .eqIfPresent(ApplicationInfoDO::getBelongType, reqVO.getBelongType())
                .betweenIfPresent(ApplicationInfoDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ApplicationInfoDO::getSignatureToolFlag, reqVO.getSignatureToolFlag())
                .in(CollectionUtil.isNotEmpty(reqVO.getUserIds()),ApplicationInfoDO::getUserId,reqVO.getUserIds())
                .orderByAsc(ApplicationInfoDO::getWeight)
                .orderByDesc(ApplicationInfoDO::getId));
    }

    default List<ApplicationInfoDO> getInstallAppList() {
        return selectList(new LambdaQueryWrapperX<ApplicationInfoDO>()
                .eq(ApplicationInfoDO::getBelongType,0)
                .eq(ApplicationInfoDO::getConsignmentFlag, 1));
    }

}